<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>宿舍管理员列表页</title>
<!-- 下载并引入jquery easyUI -->
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/gray/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/color.css">
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.8.8/jquery.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.8.8/jquery.easyui.min.js"></script>


</head>
<body>
	<table id="dormManager_dg" title="宿舍管理员列表" class="easyui-datagrid"
		style="width: 1150px; height: 480px"
		url="${param.request.contextPath}/admin/dormManagerList"
		toolbar="#dormManager_toolbar" pagination="true" rownumbers="true"
		fitColumns="true" singleSelect="true">
		<thead>
			<tr>
				<th field="cb" checkbox="true" align="center"></th>
				<th field="marName" width="50">宿舍管理员名称</th>
				<th field="sex" formatter="sexFormatter" width="50">性别</th>
				<th field="age" width="50">年龄</th>
				<th field="dormAdd" width="50">家庭住址</th>
				<th field="tel" width="50">电话号码</th>
				<th field="idNumber" width="50">身份证号码</th>
				<th field="area" width="50">负责区域</th>
			</tr>
		</thead>
	</table>

	<!-- 工具条组件 -->
	<div id="dormManager_toolbar">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-add" plain="true" onclick="newDormManager()">新增</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-edit" plain="true" onclick="editDormManager()">修改</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-remove" plain="true" onclick="destroyDormManager()">删除</a>
	</div>

	<!-- 新增和修改表单  start -->
	<div id="dormManager_dlg" class="easyui-dialog"
		style="width: 400px; height: 280px; padding: 10px 20px" closed="true"
		buttons="#dormManager_dlg-buttons">
		<div class="ftitle">宿舍管理员信息管理</div>
		<form id="dormManager_fm" enctype="multipart/form-data" method="post">
			<div class="fitem">
				<label>宿舍管理员名称:</label> <input name="marName"
					class="easyui-validatebox" data-options="required:true, missingMessage:'请输入宿舍管理员名称'">
			</div>
			<div class="fitem">
				<label>性　　别:</label>
				<input name="sex" id="sex">
			</div>
			<div class="fitem">
				<label>年　　龄:</label> <input name="age"
					class="easyui-numberspinner" data-options="min:18,max:60,precision:0,required:true,editable:true">
			</div>
			<div class="fitem">
				<label>家庭地址:</label> <input name="dormAdd"
					class="easyui-validatebox" data-options="required:true, missingMessage:'请输入家庭地址'">
			</div>
			<div class="fitem">
				<label>电话号码:</label> <input name="tel"
					class="easyui-validatebox" data-options="required:true, missingMessage:'请输入电话号码',validType:'mobile'">
			</div>
			<div class="fitem">
				<label>身份证号码:</label> <input name="idNumber" class="easyui-validatebox" 
				 data-options="required:true, validType:'idCode'">
			</div>
			<div class="fitem">
				<label>负责区域:</label> <input name="area"
					class="easyui-validatebox" data-options="required:true, missingMessage:'请输入宿舍管理员负责区域'">
			</div>
		</form>
	</div>
	<div id="dormManager_dlg-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok"
			onclick="saveDormManager()">保存</a> <a href="#" class="easyui-linkbutton"
			iconCls="icon-cancel"
			onclick="javascript:$('#dormManager_dlg').dialog('close')">取消</a>
	</div>

	<!-- 新增和修改表单 end -->

	<script type="text/javascript">
		$.extend($.fn.validatebox.defaults.rules, {
			idCode:{
		          validator:function(value,param){
		            return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(value);
		          },
		          message: '请输入正确的身份证号'
		        },
		        mobile: {
		            validator: function (value, param) {
		              return /^(?:13\d|15\d|18\d)-?\d{5}(\d{3}|\*{3})$/.test(value);
		            },
		            message: '手机号码不正确'
		          }
		});
		$('#sex').combobox({
			 data:[
				 {
					  "sexId": 0,
					  "sexName": "女"
					}
					,{
					  "sexId": 1,
					  "sexName": "男"
					}
					],
	        valueField:'sexId',
	        textField:'sexName',
	        required:'true',
	        editable:false
	        });
		function sexFormatter(value, row, index) {
			if (value == 1) {
				return '男';
			}
			return '女';
		}
		// 新增
		function newDormManager() {
			$('#dormManager_dlg').dialog('open').dialog('setTitle', '新增宿舍管理员信息');
			$('#dormManager_fm').form('clear');
			url = '${pageContext.request.contextPath}/dormManager/add';
			loadCategorySuccess(0);
		}

		// 修改
		function editDormManager() {
			$('#dormManager_fm').form('clear');
			var row = $('#dormManager_dg').datagrid('getSelected');
			if (row) {
				$('#dormManager_dlg').dialog('open').dialog('setTitle', '修改宿舍管理员信息');
				$('#dormManager_fm').form('load', row);
				url = '${pageContext.request.contextPath}/dormManager/edit?mgrId='
						+ row.mgrId;
			}
		}

		function saveDormManager() {
			$('#dormManager_fm').form('submit', {
				url : url,
				onSubmit : function() {
					return $(this).form('validate');
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (!result.success) {
						$.messager.show({
							title : 'Error',
							msg : result.errorMsg
						});
					} else {
						$.messager.show({
							title : 'Info',
							msg : result.errorMsg
						});
					}

					$('#dormManager_dlg').dialog('close'); // close the dialog
					$('#dormManager_dg').datagrid('reload'); // reload the user data
				}
			});
		}

		function destroyDormManager() {
			var row = $('#dormManager_dg').datagrid('getSelected');
			if (row) {
				$.messager
						.confirm(
								'Confirm',
								'确认删除宿舍管理员信息?',
								function(r) {
									if (r) {
										$
												.post(
														'${pageContext.request.contextPath}/dormManager/delete',
														{
															mgrId : row.mgrId
														},
														function(result) {
															if (result.success) {
																$('#dormManager_dg')
																		.datagrid(
																				'reload'); // reload the user data
															} else {
																$.messager
																		.show({ // show error message
																			title : 'Error',
																			msg : result.errorMsg
																		});
															}
														}, 'json');
									}
								});
			}
		}
	</script>
</body>
</html>